<template>
	<view class="productItem">
		<view class="user-info">
			<!-- <uni-icons type="contact" class="icon" size="26" color="#222"></uni-icons> -->
			<view class="name">
				<text>{{ source.parkingSpace }}</text>
				<uni-icons type="arrow-right" class="icon" size="20" color="#666666"></uni-icons>
				<text>{{ source.cityName }}</text>
			</view>
			<view class="status">
				{{ statusStr }}
			</view>
		</view>
		<view class="info-wrapper">
			<view class="item">
				<text class="licensePlateNo">{{ source.licensePlateNo }}</text>
				<text class="vehicleModel">({{ source.vehicleModel }})</text>
			</view>
			<view class="item">
				<text>司机：{{ source.driverName }}</text>
				<text v-if="source.driverTel">({{ source.driverTel }})</text>
			</view>
			<view class="item">
				<text>装车：{{ source.loaderName }}</text>
				<text v-if="source.loaderTel">({{ source.loaderTel }})</text>
			</view>
		</view>
		<view class="btn-wrapper">
			<view v-if="index === 0" class="date">
				计划到达：{{ source.dispatchDate }}
			</view>
			<view v-else class="date">
				实际到达：{{ source.arrivalDate }}
			</view>
			<view class="btn" @click="goDetail(source)">
				查看运输单
			</view>
			<view class="btn primary" v-if="source.status === 2" @click="arrived(source)">
				确认到站
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			index: {
				type: Number,
				default () {
					return 0
				}
			},
			source: {
				type: Object,
				default () {
					return {}
				}
			}
		},
		data() {
			return {
				statusList: ['车未到位', '装车中', '运输中', '已完成']
			}
		},
		computed: {
			statusStr() {
				const statusList = ['车未到位', '装车中', '运输中', '已完成'];
				let str = "";
				if (this.source.status === 2) {
					const pickupPointId = this.$store.state.userInfo.pickupPointId;
					if (this.source.arrivedPickupPoint && this.source.arrivedPickupPoint.indexOf(pickupPointId) > -1) {
						str = '车辆已到站'
					} else {
						str = '运输中'
					}
				} else {
					str = statusList[this.source.status]
				}
				return str;
			}
		},
		mounted() {

		},
		methods: {
			goDetail(row) {
				uni.navigateTo({
					url: '/subPage_transport/vehiclesPlanDetail?id=' + row.id + '&params=' + JSON.stringify(row)
				})
			},
			arrived() {
				uni.showModal({
					title: '到站确认',
					content: '车辆是否已到站？',
					confirmText: '已到站',
					cancelText: '未到站',
					success: (e) => {
						if (e.confirm) {
							this.confirmArrived()
						}
					}
				})
			},
			async confirmArrived() {
				const data = await this.$api.post('/app/transport/arrive', {
					id: this.source.id,
					pickupPointId: this.$store.state.userInfo.pickupPointId
				})
				this.$emit('refresh')
			},
		},
		components: {

		}
	}
</script>

<style lang="scss" scoped>
	.productItem {
		background-color: #ffffff;
		border-radius: 10upx;
		padding: 20upx;
		margin-top: 20upx;

		.user-info {
			display: flex;
			align-items: center;
			font-size: 32upx;
			padding: 0 20upx;

			.name {
				font-weight: bold;
				flex: 1;
				color: #222222;
				font-size: 34upx;
			}

			.status {
				color: #f3810e;
			}

			.icon {
				margin-right: 5upx;
			}
		}

		.region {
			padding: 0 20upx;
			color: #888888;
			margin-top: 10upx;
		}

		.info-wrapper {
			margin: 20upx 20upx;
			border-top: 1upx dashed #e1e1e1;
			border-bottom: 1upx dashed #e1e1e1;
			padding: 20upx 0;

			.item {
				display: flex;
				align-items: center;
				font-size: 32upx;
				margin-bottom: 10upx;
				color: #434343;

				.licensePlateNo {
					font-weight: bold;
					font-size: 32upx;
				}

				.vehicleModel {
					font-size: 28upx;
					color: #666;
				}
			}
		}

		.delivery-quantity {
			display: flex;
			align-items: center;
			padding: 20upx 0;
			margin-top: 20upx;
			border-top: 1upx solid #efefef;

			.item {
				flex: 1;
				font-size: 30upx;

				&.center {
					text-align: center;
				}

				&.right {
					text-align: right;
				}
			}
		}

		.btn-wrapper {
			display: flex;
			align-items: center;
			justify-content: flex-end;
			margin-top: 10upx;

			.date {
				flex: 1;
				font-size: 28upx;
				color: #666;
			}

			.btn {
				padding: 16upx 20upx;
				background-color: #ffffff;
				border: 1upx solid #bababa;
				border-radius: 10upx;
				font-size: 28upx;
				margin-left: 15upx;

				&.primary {
					color: #ffffff;
					background-color: #F26022;
					border-color: #F26022;
				}
			}
		}
	}
</style>